﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    class S_Door : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_Door ).FullName );

        private byte[] _byte = null;

        public S_Door( L1DoorInstance door )
        {
            buildPacket( door.getEntranceX(), door.getEntranceY(), door
                    .getDirection(), door.getPassable() );
        }

        public S_Door( int x, int y, int direction, int passable )
        {
            buildPacket( x, y, direction, passable );
        }

        private void buildPacket( int x, int y, int direction, int passable )
        {
            writeC( Opcodes.S_OPCODE_ATTRIBUTE );
            writeH( x );
            writeH( y );
            writeC( direction ); // ドアの方向 0: ／ 1: ＼
            writeC( passable );
        }


        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_Door";
        }
    }
}
